package com.itany.corejava.code07_面向对象;

import java.util.Scanner;

/**
 * @author 石小俊
 * @date 2023年04月17日 13:40
 */
public class Test03_全局变量与局部变量 {

    public static void main(String[] args) {
        Account account = new Account();
        account.name = "admin";
        account.money = 5000;
        account.show("alice");
        account.test();

        System.out.println("**********************");
        Account account2 = new Account();
        account2.name = "jack";
        account2.money = 8000;
        account2.show("tom");
        account2.test();
        System.out.println("**********************");
        Account account3 = new Account();
        account3.name = "张三";
        account3.money = 10000;
        account3.showMenu();
    }
}

class Account {
    // 全局变量
    String name;
    double money;

    // 方法参数属于局部变量
    public void show(String name) {
        // 局部变量
        double money = 10000;
        System.out.println(this.name);
        System.out.println(money);
    }

    public void test() {
        System.out.println(name);
        System.out.println(this.money);
    }

    // 1.查询余额,打印出户主姓名与账户余额
    public void queryMoney() {
        System.out.println("姓名:" + name + ",当前账户余额:" + money);
    }

    // 2.存钱,打印存储了多少钱,存储后账户余额
    public void saveMoney(double money) {
        this.money += money;
        System.out.println("您存储了" + money + "元,当前账户余额:" + this.money);
    }

    // 3.转账,打印谁给你转账,转了多少钱,转账后账户余额是多少
    public void transfer(String name, double money) {
        this.money += money;
        System.out.println(name + "向您转账" + money + "元,当前账户余额:" + this.money);
    }

    // 4.取钱,打印取出了多少钱,剩余的账户余额是多少
    public void getMoney(double money) {
        this.money -= money;
        System.out.println("您提取了" + money + "元,当前账户余额:" + this.money);
    }

    public void showMenu(){
        Scanner sc = new Scanner(System.in);
        System.out.println("-----------------------------------");
        System.out.println("欢迎使用账户管理系统,系统提供以下功能:1.查询余额 2.存钱 3.转账 4.取钱 5.退出");
        while (true){
            System.out.println("-----------------------------------");
            System.out.print("请选择对应系统功能完成您的业务(1-5):");
            int choice = sc.nextInt();
            switch (choice){
                case 1:
                    queryMoney();
                    break;
                case 2:
                    System.out.print("请输入存储的金额:");
                    double money = sc.nextDouble();
                    saveMoney(money);
                    break;
                case 3:
                    System.out.print("谁向您转账:");
                    String name = sc.next();
                    System.out.print("请输入转账金额:");
                    money = sc.nextDouble();
                    transfer(name,money);
                    break;
                case 4:
                    System.out.print("请输入提取的金额:");
                    money = sc.nextDouble();
                    getMoney(money);
                    break;
                case 5:
                    System.out.println("您已经退出,欢迎下次光临");
                    return;
                default:
                    System.out.println("您选择的菜单有误,请重新选择");
                    break;
            }
        }
    }
}
